package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by v on 17-5-4.
 */

@WebServlet(name = "Registered",value = "/Registered")
public class Registered extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //把form表单的元素抓取下来
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        String repassword=req.getParameter("repassword");
        String sex=req.getParameter("sex");
        String question=req.getParameter("question");
        String answer=req.getParameter("answer");
        String email=req.getParameter("email");

        if(password.equals(repassword)){
            Sql sql=Sql.getSql();
            sql.write(username,password,sex,question,answer,email);
        }

        resp.sendRedirect("/index.html");
    }
}
